package com.etrans.baf.analyse.util;

import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@EtCommentAnnotation(type="class",desc="数据库通讯层")
public abstract class BaseService {
	public static final Logger logger = LoggerFactory.getLogger(BaseService.class);

	protected String masterAliases = "masterAliases";
 	
	protected abstract SqlSessionTemplate getMasterSessionTemplate();
	
	
	@EtCommentAnnotation(type="method",desc="更新数据")
	protected void update(String statementName,Object param){
		this.getMasterSessionTemplate().update(masterAliases+"."+statementName, param);
	}
	
	@EtCommentAnnotation(type="method",desc="更新数据,返回影响行数")
	protected int updateForReturn(String statementName,Object param){
	   return this.getMasterSessionTemplate().update(masterAliases+"."+statementName, param);
	}
	
	@EtCommentAnnotation(type="method",desc="插入数据")
	protected Object insert(String statementName,Object param){
		return this.getMasterSessionTemplate().insert(masterAliases+"."+statementName, param);
	}
	
	protected int insertForReturn(String statementName,Object param){
		return this.getMasterSessionTemplate().insert(masterAliases+"."+statementName, param);
	}
	
	@EtCommentAnnotation(type="method",desc="删除数据")
	protected void delete(String statementName,Object param){
		this.getMasterSessionTemplate().delete(masterAliases+"."+statementName, param);
	}
	
	@EtCommentAnnotation(type="method",desc="返回list")
	protected Object select(String statementName,Object param){
		return this.getMasterSessionTemplate().selectList(masterAliases+"."+statementName,param);
	}
	
	@EtCommentAnnotation(type="method",desc="返回单个对象")
	protected Object selectOne(String statementName,Object param){
		return this.getMasterSessionTemplate().selectOne(masterAliases+"."+statementName,param);
	}
}
